﻿
using System;
using System.Globalization;
using System.Web.Mvc;


namespace Nasa8x.Mvc.Helpers
{
    public static class MetaHelper
    {



        public static string Title(this HtmlHelper html, string title)
        {
            return html.Title(title, null);
        }

        public static string Title(this HtmlHelper html, string title, params string[] formats)
        {

            //format the title 
            if (formats != null && formats.Length > 0)
            {
                title = string.Format(title, formats);
            }

            //format title value, combine base with title 
            // string titleValueFormatted = string.Format(baseValue, titleValue); 
            return string.Format("<title>{0}</title>", html.Encode(title));
        }


        public static string Keywords(this HtmlHelper html, string value)
        {
            return html.Keywords(value, null);
        }

        public static string Keywords(this HtmlHelper html, string value, params string[] formats)
        {

            //format the title 
            if (formats != null && formats.Length > 0)
            {
                value = string.Format(value, formats);
            }


            return string.Format("<meta name=\"keywords\" content=\"{0}\" />", html.Encode(value));
        }


        public static string Description(this HtmlHelper html, string value)
        {
            return html.Description(value, null);
        }


        public static string Description(this HtmlHelper html, string value, params string[] formats)
        {

            //format the title 
            if (formats != null && formats.Length > 0)
            {
                value = string.Format(value, formats);
            }


            return string.Format("<meta name=\"description\" content=\"{0}\" />", html.Encode(value));
        }



        public static string MetaDate(this HtmlHelper html)
        {
            return html.MetaDate(DateTime.UtcNow, null);
        }

        public static string MetaDate(this HtmlHelper html, DateTime value)
        {
            return html.MetaDate(value, null);
        }


        public static string MetaDate(this HtmlHelper html, DateTime value, int? dayAgo)
        {

            
            if (dayAgo.HasValue)
            {
                value += TimeSpan.FromDays(dayAgo.Value);
            }

            return string.Format("<meta name=\"date\" content=\"{0}\" />", value.ToString("yyyy-MM-ddTHH:mm:sszzz", new DateTimeFormatInfo()));
        }








    }
}
